package com.SouthernWall_404.Age_Capitalism.common.Network.ClientHandler;

import com.SouthernWall_404.Age_Capitalism.common.Gui.Menu.ModMerchantMenu;
import com.SouthernWall_404.Age_Capitalism.common.Gui.Menu.ModSettingMerchantMenu;
import com.SouthernWall_404.Age_Capitalism.common.Network.S2C.MerchantServerPacket;
import net.minecraft.client.Minecraft;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.trading.MerchantOffers;
import net.minecraftforge.network.NetworkEvent;

import java.util.function.Supplier;

public class MerchantClientHandler {
    public static void handleOpenPacket(MerchantServerPacket p_105034_, Supplier<NetworkEvent.Context> ctx)
    {
//        ClientMerchantData.setOffers(msg.getOffers());
        AbstractContainerMenu abstractcontainermenu =Minecraft.getInstance().player.containerMenu;
        if (p_105034_.getContainerId() == abstractcontainermenu.containerId && abstractcontainermenu instanceof ModMerchantMenu merchantmenu) {
            merchantmenu.setOffers(new MerchantOffers(p_105034_.getOffers().createTag()));
            merchantmenu.setXp(p_105034_.getVillagerXp());
            merchantmenu.setMerchantLevel(p_105034_.getVillagerLevel());
            merchantmenu.setShowProgressBar(p_105034_.showProgress());
            merchantmenu.setCanRestock(p_105034_.canRestock());
        }

        if (p_105034_.getContainerId() == abstractcontainermenu.containerId && abstractcontainermenu instanceof ModSettingMerchantMenu merchantmenu) {
            merchantmenu.setOffers(new MerchantOffers(p_105034_.getOffers().createTag()));
            merchantmenu.setXp(p_105034_.getVillagerXp());
            merchantmenu.setMerchantLevel(p_105034_.getVillagerLevel());
            merchantmenu.setShowProgressBar(p_105034_.showProgress());
            merchantmenu.setCanRestock(p_105034_.canRestock());
        }
    }
}
